using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Services;

namespace ConsoleApi.Controllers;

/// <summary>
/// MCP测试控制器
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class McpTestController : ControllerBase
{
    private readonly TestMcpService _testMcpService;

    public McpTestController(TestMcpService testMcpService)
    {
        _testMcpService = testMcpService;
    }

    /// <summary>
    /// 测试MCP连接
    /// </summary>
    [HttpGet("test")]
    public IActionResult TestMcp()
    {
        try
        {
            var result = _testMcpService.TestConnection();
            return Ok(new { 
                Success = true, 
                Message = result,
                Timestamp = DateTime.Now,
                McpEndpoint = "/mcp"
            });
        }
        catch (Exception ex)
        {
            return BadRequest(new { 
                Success = false, 
                Error = ex.Message,
                Timestamp = DateTime.Now
            });
        }
    }

    /// <summary>
    /// 获取服务器信息
    /// </summary>
    [HttpGet("info")]
    public IActionResult GetServerInfo()
    {
        try
        {
            var info = _testMcpService.GetServerInfo();
            return Ok(new { 
                Success = true, 
                Info = info,
                Timestamp = DateTime.Now
            });
        }
        catch (Exception ex)
        {
            return BadRequest(new { 
                Success = false, 
                Error = ex.Message,
                Timestamp = DateTime.Now
            });
        }
    }

    /// <summary>
    /// 测试计算功能
    /// </summary>
    [HttpGet("calculate")]
    public IActionResult Calculate(
        [FromQuery] double a, 
        [FromQuery] string operation, 
        [FromQuery] double b)
    {
        try
        {
            var result = _testMcpService.Calculate(a, operation, b);
            return Ok(new { 
                Success = true, 
                Result = result,
                Calculation = $"{a} {operation} {b}",
                Timestamp = DateTime.Now
            });
        }
        catch (Exception ex)
        {
            return BadRequest(new { 
                Success = false, 
                Error = ex.Message,
                Timestamp = DateTime.Now
            });
        }
    }
} 